package aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import pojo.User;

import java.util.HashMap;
import java.util.Map;

@Aspect
@Component
public class CacheMap {
    private Map<Integer, User> map=new HashMap<Integer, User>();
    @Around("execution(* service..*.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
//        获取方法对应的参数列表中的值
        Object[] args=joinPoint.getArgs();

        int id= (int) args[0];
        User user=map.get(id);
        if(user==null){
            System.out.println("没有缓存");
            user= (User) joinPoint.proceed();
            map.put(id,user);
        }else {
            System.out.println("有缓存");

        }

        return user;
    }
}






























